package com.wanshi.utils;

import java.lang.reflect.Method;
import java.util.concurrent.Callable;

@SuppressWarnings("all")
public class DatiTask<T>  implements Callable{

    private String name;
    private String method;
    private Object[] objs;


    public DatiTask(String name,String method,Object[] objs){
        this.name = name;
        this.method = method;
        this.objs =objs;
    };

    @Override
    public T call() throws Exception {
        //3 反射调方法
        Class<?> c = Class.forName(name);
        // 反射类的方法：
        Method[] ms = c.getMethods();
        for (int i = 0; i < ms.length; i++) {
            String methodName = ms[i].getName();
            if(methodName.equals(method)){
                T t = (T) ms[i].invoke(c.getDeclaredConstructor().newInstance(),objs);
                return t;
            }
        }
        return null;
    }
}
